<script setup>
import {
  ref
} from 'vue'

/**
 * 弹窗实例
 */
const popupRef = ref(null)

/**
 * 显示
 */
const show = () => {
  popupRef.value.open()
}

/**
 * 隐藏
 */
const hide = () => {
  popupRef.value.close()
}

/**
 * 登出
 */
const handleLogout = () => {
  uni.showModal({
    title: "退出登录",
    content: "是否确定退出登录？",
    success: () => {
      uni.removeStorage({
        key: "token",
        success: () => {
          uni.showToast({
            title: "登出成功",
            icon: "success",
            musk: true
          })
          setTimeout(() => {
            uni.reLaunch({
              url: '/frame/pages/login/index'
            })
          }, 1000)
        }
      })
    }
  })
}

/**
 * 暴露
 */
defineExpose({
  show
})
</script>

<template>
  <uni-popup ref="popupRef" :isMaskClick="true" type="bottom">
    <view class="popup-time-wrap">
      <view class="form-wrap">
        <view class="form-title">
          <view class="form-title-left">
            设置
          </view>
          <image class="form-title-right" src="/static/icon/icon-close.svg" @click="hide"></image>
        </view>
        <view class="form-btn">
          <view class="btn-item" @click="handleLogout">
            退出登录
          </view>
          <view class="btn-item" @click="hide">
            取消
          </view>
        </view>
      </view>
    </view>
  </uni-popup>
</template>

<style scoped src="./index.scss">

</style>